package com;


import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class CheckFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        HttpSession httpSession = httpServletRequest.getSession();
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        if(httpSession.getAttribute("Logined")==null){
            httpServletResponse.sendRedirect(((HttpServletRequest) request).getContextPath()+"/Login.jsp");
        }
        else{
            httpSession.setAttribute("Logined",true);
            chain.doFilter(request, response);
        }
    }
}
